<template>
  <el-dialog
    v-model="state.visible"
    :show-close="false"
    width="600"
    align-center
    class="cusdia"
    @opened="getTree"
  >
    <template #header="{ close }">
      <div class="my-header">
        <h4 class="titleClass">添加录像</h4>
        <el-icon class="titleClose" @click="close">
          <CloseBold />
        </el-icon>
      </div>
    </template>

    <div class="main">
      <el-form :model="state.form" label-width="auto">
        <el-form-item label="设备编码">
          <el-input v-model="state.cameraId" />
        </el-form-item>
        <el-form-item label="录像日期">
          <el-date-picker
            v-model="state.cdate"
            type="date"
            format="YYYY-MM-DD"
            placeholder="选择日期"
            style="width: 150px"
          />
          <el-time-picker
            v-model="state.dts"
            is-range
            format="HH:mm"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="截止时间"
            style="width: 150px; margin-left: 20px"
          />
        </el-form-item>
      </el-form>
    </div>

    <template #footer>
      <div class="my-footer">
        <el-button type="" class="diabtn" @click="state.visible = false"
          >取消</el-button
        >
        <el-button type="primary" class="diabtn" @click="ok">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { Calendar, Search } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";

const props = defineProps({
  isShow: Boolean,
});
const state = reactive({
  visible: false,
  cameraId: "",
  cdate: null,
  dts: [],
});

const emits = defineEmits(["ok"]);
watch(
  () => props.isShow,
  (newValue) => {
    if (newValue) {
      // 如果isShow为true，清空表单字段
      state.cameraId = "";
      state.cdate = null;
      state.dts = [];
    }
    state.visible = newValue;
  }
);

const ok = () => {
  if (state.cameraId == "") {
    ElMessage.error("请输入设备编码");
    return;
  }
  if (state.cdate == null) {
    ElMessage.error("请选择日期");
    return;
  }
  if (state.dts.length == 0) {
    ElMessage.error("请选择时间段");
    return;
  }
  emits("ok", { cameraId: state.cameraId, cdate: state.cdate, dts: state.dts });
  state.visible = false;
};
</script>

<style scoped lang="scss">
.main {
  padding: 25px 20px;
  display: flex;
  flex-direction: column;
  .tt {
    height: 30px;
    align-content: center;
    font-weight: 600;
    font-size: 16px;
    color: #293555;
  }
  .tr {
    height: 580px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    .ts {
      height: 40px;
      line-height: 40px;
      margin: 5px 0;
    }
  }
}
.my-header {
  height: 50px;
  background: #6e8dfb;
  display: flex;
  align-items: center;
  padding: 0 25px;
  .titleClass {
    font-weight: 600;
    font-size: 16px;
    color: #ffffff;
  }
  .titleClose {
    margin-left: auto;
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
  }
}
.my-footer {
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-top: 1px solid #ccddf7;
  .diabtn {
    width: 130px;
    height: 40px;
    font-size: 16px;
    border-radius: 6px;
  }
}
</style>

<style lang="scss">
.cusdia {
  background: linear-gradient(134deg, #e9effb 0%, #fbfcff 100%);
  box-shadow: 3px 3px 16px 0px rgba(159, 177, 206, 0.7);
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
  .el-dialog__footer {
    padding: 0;
  }
}
</style>
